//
//  LBHomeFunctionListView.m
//  爱鲜蜂
//
//  Created by 李田 on 16/11/8.
//  Copyright © 2016年 tianyao. All rights reserved.
//

#import "LBHomeFunctionListView.h"
#import "LBHomeFunctionFlowLayout.h"
#import "LBHomeFunctionFirstCell.h"
#import "LBHomeFunctionScollCell.h"
#import "LBHomeFunctionDimeStoreCell.h"
#import "LBHomeFunctionCategoryCell.h"
@interface LBHomeFunctionListView ()<UICollectionViewDataSource, UICollectionViewDelegate>

@end

static NSString *cellID = @"cell_ID";
static NSString *topCellID = @"topCell_ID";
static NSString *scrollCellID = @"scrollCell_ID";
static NSString *dimeStoreCellID = @"dimeStoreCell_ID";
static NSString *categoryCellID = @"categoryCell_ID";
@implementation LBHomeFunctionListView

- (instancetype)initWithFrame:(CGRect)frame{
    
    if (self = [super initWithFrame:frame]) {
        
        [self setupUI];
    }
    return self;
}

#pragma mark - 1.0 创建collectionV
- (void)setupUI{
    
    LBHomeFunctionFlowLayout *flowLayout = [[LBHomeFunctionFlowLayout alloc] init];
    
    UICollectionView *collectionV = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:flowLayout];
    //    MARK:设置背景颜色
    collectionV.backgroundColor = [UIColor cz_colorWithHex:0xf5f5f9];
    [self addSubview:collectionV];
    
    //    MARK:代理
    collectionV.dataSource = self;
    
    collectionV.delegate = self;
    
    
    //    MARK: 注册
     [collectionV registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:cellID];
    
    [collectionV registerClass:[LBHomeFunctionFirstCell class] forCellWithReuseIdentifier:topCellID];
   
    [collectionV registerClass:[LBHomeFunctionScollCell class] forCellWithReuseIdentifier:scrollCellID];
    
    [collectionV registerClass:[LBHomeFunctionDimeStoreCell class] forCellWithReuseIdentifier:dimeStoreCellID];
    
    [collectionV registerClass:[LBHomeFunctionCategoryCell class] forCellWithReuseIdentifier:categoryCellID];
    //    MARK: 设置大小
    [collectionV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.equalTo(self);
        make.top.equalTo(self).offset(-64);
    }];
    
}

#pragma mark - 2.0 设置数据源
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    
    return 9;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    
    if (section == 0 || section == 1) {
        return 1;
    }else{
        
        return 1;
    }
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    NSString *identifier = cellID;
    if (indexPath.section == 0) {

        identifier = topCellID;
    }else if (indexPath.section == 1){
        
        identifier = scrollCellID;
    }else if (indexPath.section == 2){
        
        identifier = dimeStoreCellID;
    }else{
        identifier = categoryCellID;
    }
    
            UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
    
//    cell.backgroundColor = [UIColor cz_randomColor];
 return cell;
}

#pragma mark - 
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    CGFloat width = [UIScreen mainScreen].bounds.size.width;

    if (indexPath.section == 0) {
               CGFloat height = 240;
        
        return CGSizeMake(width, height);
    }else if(indexPath.section == 1){
        
        return CGSizeMake(width, 140);
    }else if(indexPath.section == 3){
        
        return CGSizeMake(width, 360);
    }else{
         return CGSizeMake(width, 320);
    }
    
//    return CGSizeMake(, 80);
}
@end




